<template>
  <div class="content">
    <h1 class="title">
      <slot name="title"></slot>
    </h1>
    <hr>
    <ul>
      <li class="list-title">
        <div class="song-item">
          <span class="item-index"></span>
          <span class="item-title">歌曲名</span>
          <span class="item-name">歌手</span>
          <span class="item-intro">专辑</span>
        </div>
      </li>
      <li class="list-content" v-for="(item, index) in songList" :key="index">
        <div class="song-item" :class="{'is-play': id === item.id}">
          <span class="item-index">
            <span v-if="id !== item.id">{{index + 1}}</span>
            <svg v-if="id === item.id" class="icon" aria-hidden="true">
              <use :xlink:href="YINLIANG"></use>
            </svg>
          </span>
          <span class="item-title" @click="toplay(item.id, item.url, item.pic, index, item.name, item.lyric)">{{replaceFName(item.name)}}</span>
          <span class="item-name">{{replaceLName(item.name)}}</span>
          <span class="item-intro">{{item.introduction}}</span>
          <el-button class="el-button-del" v-if="isUser" @click="deleteCollection(item.id)">取消收藏</el-button>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
import mixin from '../mixin'
import { mapGetters } from 'vuex'
import { ICON } from '../assets/icon/index'
import {HttpManager} from "../api";

export default {
  name: 'album-content',
  mixins: [mixin],
  props: {
    songList: Array,
    isUser: {
      type: Boolean,
      default: false,
    },
    songListId: Number
  },
  data () {
    return {
      YINLIANG: ICON.YINLIANG
    }
  },
  computed: {
    ...mapGetters([
      'id', // 音乐ID
      'userId'
    ])
  },
  methods: {
    deleteCollection (id) {
      let params = new URLSearchParams()
      params.append('userId', this.userId)
      params.append('songId', id)
      params.append('songListId', this.songListId)
      HttpManager.deleteCollection(params).then(res => {
        if (res.code === 1) {
          // this.getData()
          this.registerForm = {}
          this.notify('取消成功', 'success')
          this.$router.go(0)
        } else {
          this.notify('取消失败', 'error')
        }
      }).catch(err => {
        console.log(err)
      })
    }
  }
}
</script>

<style lang="scss" scoped>
@import '../assets/css/album-content.scss';
</style>
